package com.nulldev.util.web.nTubeExtensions.gvc_spoofer;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.regex.Pattern;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.data.Arrays.maps.FastMaps;
import com.nulldev.util.io.FastIO.FastIO;

public class GVCPostDataGenerator {

	private static final char[][] Zca = new char[5][];
	private static final Map<Object, Integer> ug = FastMaps.map(64);

	static {
		final char[] a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
		final String[] b = new String[]
			{ "+/=", "+/", "-_=", "-_.", "-_" };
		for (int c = 0; 5 > c; c++) {
			final char[] d = ArrayUtils.addAll(a, b[c].toCharArray());
			Zca[c] = d;
			for (int e = 0; e < d.length; e++) {
				int f = d[e];
				ug.put(f, e);
			}
		}
	}

	private static final Pattern p = Pattern.compile("^[\\s\\xa0]*$");

	private static boolean fc(final int n) {
		return p.matcher("" + (char) n).matches();
	}

	private static int c(final AtomicInteger d, int m, final char[] a) {
		for (; d.get() < a.length;) {
			int n = a[d.getAndIncrement()];
			Object p = ug.get(n);
			if (null != p)
				return (int) p;
			if (!fc(n))
				throw new RuntimeException("Unknown base64 encoding at char: " + n);
		}
		return m;
	}

	private static void ada(final char[] a, final Consumer<Integer> object) {
		final AtomicInteger d = new AtomicInteger(0);
		for (;;) {
			int e = c(d, -1, a);
			int f = c(d, 0, a);
			int h = c(d, 64, a);
			int l = c(d, 64, a);
			if (64 == l && -1 == e)
				break;
			object.accept(e << 2 | f >> 4);
			if (64 != h) {
				object.accept(f << 4 & 240 | h >> 2);
			}
			if (64 != l) {
				object.accept(h << 6 & 192 | l);
			}
		}
	}

	private static boolean ic(final String a, final char b) {
		return -1 != a.indexOf(b);
	}

	public static int[] tg(final char[] a) {
		int b = a.length;
		int c = 3 * b / 4;
		if ((c % 3) != 0) {
			c = (int) Math.floor(c);
		} else {
			if (ic("=.", a[b - 1])) {
				if (ic("=.", a[b - 2])) {
					c -= 2;
				} else {
					c -= 1;
				}
			}

		}

		final int[] d = new int[c];

		final AtomicInteger e = new AtomicInteger(0);
		ada(a, new Consumer<Integer>() {
			@Override
			public void accept(final Integer f) {
				d[e.getAndIncrement()] = f;
			}
		});

		return e.get() != c ? Arrays.copyOfRange(d, 0, e.get()) : d;
	}

	public static void main(String[] args) {
		final int[] out = tg("IjqyE7IS1_YR5vF0xifTafhi0yDka-VF3lDrath2xGPTZfB5-1zxdPhC5lH7".toCharArray());
		ArrayUtils.println(out);
		FastIO.get().flush();
		JVM.exit();
	}
}
